<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="98px">
      <el-form-item label="工程名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入工程名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="建设单位" prop="constructionUnit">
        <el-input
          v-model="queryParams.constructionUnit"
          placeholder="请输入建设单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <!-- <el-form-item label="预计投标时间">
        <el-date-picker
          v-model="daterangeEstimatedBidTime"
          style="width: 210px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item> -->

      <!-- 以下为高级查询 -->
      <el-form-item label="项目编号" prop="projectNumber" >
        <el-input
          v-model="queryParams.projectNumber"
          placeholder="请输入项目编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区域" prop="region" >
        <el-input
          v-model="queryParams.region"
          placeholder="请输入区域"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="招标形式" prop="bidForm"  v-show="showHighSearch">
        <el-input
          v-model="queryParams.bidForm"
          placeholder="请输入招标形式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="工程面积" prop="projectArea"  v-show="showHighSearch">
        <el-input
          v-model="queryParams.projectArea"
          placeholder="请输入工程面积"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工程地址" prop="address" v-show="showHighSearch">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入工程地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工程造价" prop="projectCost" v-show="showHighSearch">
        <el-input
          v-model="queryParams.projectCost"
          placeholder="请输入工程造价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->

      <el-form-item label="申办人姓名" prop="sponsorName" >
        <el-input
          v-model="queryParams.sponsorName"
          placeholder="请输入申办人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="审核人" prop="auditor" >
        <el-select
            v-model="queryParams.auditor"
            filterable
            default-first-option
            placeholder="请选择或输入审核人">
            <el-option
              v-for="item in auditorOptions"
              :key="item.userId"
              :label="item.userName"
              :value="item.userId">
            </el-option>
          </el-select>
      </el-form-item>

       <el-form-item label="申办时间" >
        <el-date-picker
          v-model="daterangeSponsorTime"
          style="width: 210px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="状态" prop="bidProjectStatus">
        <el-select v-model="queryParams.bidProjectStatus" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.bid_project_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <!-- <el-form-item label="申报人电话" prop="sponsorPhone" v-show="showHighSearch">
        <el-input
          v-model="queryParams.sponsorPhone"
          placeholder="请输入申报人电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="申办时间" v-show="showHighSearch">
        <el-date-picker
          v-model="daterangeSponsorTime"
          style="width: 210px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="业务跟踪人" prop="tracker" v-show="showHighSearch">
        <el-input
          v-model="queryParams.tracker"
          placeholder="请输入业务跟踪人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <!-- <el-button type="success" icon="el-icon-search" size="mini" @click='showHighSearch=!showHighSearch'>高级搜索</el-button> -->
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:my_bid_project:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:my_bid_project:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:my_bid_project:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:my_bid_project:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="bid_projectList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="项目编号" align="center" prop="projectNumber" fixed />
      <el-table-column label="区域" align="center" prop="region" fixed/>
      <el-table-column label="工程名称" width="200" align="left" prop="projectName" fixed/>
      <el-table-column label="建设单位" align="center" prop="constructionUnit" fixed />
      <!-- <el-table-column label="当前进度" align="center" prop="currentStepStr" />
      <el-table-column label="招标形式" align="center" prop="bidForm" />
      <el-table-column label="工程面积(平方米)" align="center" prop="projectArea" width="150"/>
      <el-table-column label="工程地址" align="center" prop="address" />
      <el-table-column label="工程造价(万元)" align="center" prop="projectCost" width="110" />
      <el-table-column label="预计投标时间" align="center" prop="estimatedBidTime" width="110">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.estimatedBidTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
       -->
      <el-table-column label="申办人姓名" align="center" prop="sponsorName"  width="100"/>
      <el-table-column label="审核人" align="center" prop="auditorName"  width="100"/>
      <!-- <el-table-column label="申报人电话" align="center" prop="sponsorPhone"  width="100"/> -->
      <el-table-column label="申办时间" align="center" prop="sponsorTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.sponsorTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="是否缴保证金" align="center" prop="paymentDepsit" width="110">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.paymentDepsit"/>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="保证金缴纳金额(元)" align="center" prop="depsitMoney" width="140" />
      <el-table-column label="保证金缴纳时间" align="center" prop="paymentDepsitTime" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.paymentDepsitTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="保证金缴纳方式" align="center" prop="depsitType"  width="120">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.pm_project_item_pay_type" :value="scope.row.depsitType"/>
        </template>
      </el-table-column>
      <!-- <el-table-column label="是否需要现场收据" align="center" prop="depsitReceipt"  width="130">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.depsitReceipt"/>
        </template>
      </el-table-column>
      <el-table-column label="业务跟踪人" align="center" prop="tracker" width="100" /> -->
      <el-table-column label="登记人" align="center" prop="creator" width="100" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document"
            @click="handleDetail(scope.row)"
          >详情</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:my_bid_project:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:my_bid_project:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改基本信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1100px"
    :close-on-click-modal="false" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-row>
          <el-col :span="8">
        <el-form-item label="项目编号" prop="projectNumber">
          <el-input v-model="form.projectNumber" placeholder="请输入项目编号" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="区域" prop="region">
          <el-input v-model="form.region" placeholder="请输入区域" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="招标形式" prop="bidForm">
          <el-input v-model="form.bidForm" placeholder="请输入招标形式" />
        </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
        <el-form-item label="工程名称" prop="projectName">
          <el-input v-model="form.projectName" placeholder="请输入工程名称" />
        </el-form-item>
          </el-col>

          <el-col :span="8">
        <el-form-item label="工程面积(平方米)" prop="projectArea">
          <el-input v-model="form.projectArea" placeholder="请输入工程面积" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="工程地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入工程地址" />
        </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
        <el-form-item label="工程造价(万元)" prop="projectCost">
          <el-input v-model="form.projectCost" placeholder="请输入工程造价" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="预计投标时间" prop="estimatedBidTime">
          <el-date-picker clearable
            v-model="form.estimatedBidTime"
            type="date"
            style="width:200px"
            value-format="yyyy-MM-dd"
            placeholder="请选择预计投标时间">
          </el-date-picker>
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="建设单位" prop="constructionUnit">
          <el-input v-model="form.constructionUnit" placeholder="请输入建设单位" />
        </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
        <el-form-item label="申办人姓名" prop="sponsorName">
          <el-input v-model="form.sponsorName" placeholder="请输入申办人姓名" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="申报人电话" prop="sponsorPhone">
          <el-input v-model="form.sponsorPhone" placeholder="请输入申报人联系电话" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="申办时间" prop="sponsorTime">
          <el-date-picker clearable
            v-model="form.sponsorTime"
            type="date"
            style="width:200px"
            value-format="yyyy-MM-dd"
            placeholder="请选择申办时间">
          </el-date-picker>
        </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
        <el-form-item label="审核人" prop="auditor">
          <el-select
            v-model="form.auditor"
            filterable
            allow-create
            default-first-option
            placeholder="请选择或输入审核人">
            <el-option
              v-for="item in auditorOptions"
              :key="item.userId"
              :label="item.userName"
              :value="item.userId">
            </el-option>
          </el-select>
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="是否要现场收据" prop="depsitReceipt">
          <el-select v-model="form.depsitReceipt" placeholder="请选择是否需要现场收据" style="width:200px" >
            <el-option
              v-for="dict in dict.type.sys_yes_no"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="是否缴纳保证金" prop="paymentDepsit">
          <el-select v-model="form.paymentDepsit" placeholder="请选择是否缴纳保证金" style="width:200px" @change="bclxChange">
            <el-option
              v-for="dict in dict.type.sys_yes_no"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
        <el-form-item label="保证金缴纳方式" prop="depsitType" v-if="isJxBc">
          <el-select v-model="form.depsitType" placeholder="请选择保证金缴纳方式" >
            <el-option
              v-for="dict in dict.type.pm_project_item_pay_type"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="保证金缴纳金额(元)" prop="depsitMoney" v-if="isJxBc">
          <el-input type="number" v-model="form.depsitMoney" placeholder="请输入保证金缴纳金额" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="保证金缴纳时间" prop="paymentDepsitTime" v-if="isJxBc">
          <el-date-picker clearable
            v-model="form.paymentDepsitTime"
            type="date"
            style="width:200px"
            value-format="yyyy-MM-dd"
            placeholder="请选择保证金缴纳时间">
          </el-date-picker>
        </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
        <el-form-item label="业务跟踪人" prop="tracker">
          <el-input v-model="form.tracker" placeholder="请输入业务跟踪人" />
        </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="状态" prop="bidProjectStatus">
              <el-select v-model="form.bidProjectStatus" placeholder="请选择状态" style="width:200px" @change="bclxChange">
                <el-option
                  v-for="dict in dict.type.bid_project_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          </el-row>
      <el-divider content-position="center">项目人员管理</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddBidProjectPresonMap">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteBidProjectPresonMap">删除</el-button>
          </el-col>
        </el-row>
        <el-table :data="bidProjectPresonMapList" :row-class-name="rowBidProjectPresonMapIndex" @selection-change="handleBidProjectPresonMapSelectionChange" ref="bidProjectPresonMap">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="" align="center" prop="index" width="250"/>
          <el-table-column label="人员" >
            <template slot-scope="scope">
                <el-cascader
                v-model="scope.row.selectedPerson"
                :options="personOptions"
                :props="{ expandTrigger: 'hover' }" placeholder="请选择人员"
                @change="((val)=>validPerson(val,scope.row.selectedPerson))">
              </el-cascader>
            </template>
          </el-table-column>
          <el-table-column label="人员是否锁定" >
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.locked"
                active-color="#ff4949">
              </el-switch>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 投标项目详情 -->
    <el-dialog title="项目详情" :visible.sync="detailOpen" width="1100px" append-to-body>
      <el-form ref="detailForm" :model="detailForm" label-width="150px">
        <el-row>
          <el-col :span="8">
        <el-form-item label="项目编号:">
          <span>{{detailForm.projectNumber}}</span>
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="区域:" >
          <span>{{detailForm.region}}</span>
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="招标形式:" >
          <span>{{detailForm.bidForm}}</span>
        </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
        <el-form-item label="工程名称:" >
          <span>{{detailForm.projectName}}</span>
        </el-form-item>
          </el-col>

          <el-col :span="8">
        <el-form-item label="工程面积(平方米):" >
          <span>{{detailForm.projectArea}}</span>
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="工程地址:" >
          <span>{{detailForm.address}}</span>
        </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
        <el-form-item label="工程造价(万元):">
          <span>{{detailForm.projectCost}}</span>
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="预计投标时间:" >
          <span>{{ parseTime(detailForm.estimatedBidTime, '{y}-{m}-{d}') }}</span>
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="建设单位:">
          <span>{{detailForm.constructionUnit}}</span>
        </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
        <el-form-item label="申办人姓名:" >
          <span>{{detailForm.sponsorName}}</span>
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="申报人电话:" >
          <span>{{detailForm.sponsorPhone}}</span>
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="申办时间:">
          <span>{{ parseTime(detailForm.sponsorTime, '{y}-{m}-{d}') }}</span>
        </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
        <el-form-item label="业务跟踪人:" >
          <span>{{detailForm.tracker}}</span>
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="审核人:" >
          <span>{{detailForm.auditorName}}</span>
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="是否要现场收据:" >
          <dict-tag :options="dict.type.sys_yes_no" :value="detailForm.depsitReceipt"/>
        </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
        <el-form-item label="是否缴纳保证金:" >
          <dict-tag :options="dict.type.sys_yes_no" :value="detailForm.paymentDepsit"/>
        </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否缴纳保证金:" >
              <dict-tag :options="dict.type.sys_yes_no" :value="detailForm.paymentDepsit"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="状态:" >
              <dict-tag :options="dict.type.bid_project_status" :value="detailForm.bidProjectStatus"/>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-row>
          <el-col :span="8">
        <el-form-item label="保证金缴纳方式:" prop="depsitType" v-if="isDetailJxBc">
        <dict-tag :options="dict.type.pm_project_item_pay_type" :value="detailForm.depsitType"/>
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="保证金缴纳金额(元):" v-if="isDetailJxBc">
          <el-input type="number" v-model="detailForm.depsitMoney"/>
        </el-form-item>
          </el-col>
          <el-col :span="8">
        <el-form-item label="保证金缴纳时间:" v-if="isDetailJxBc">
          <span>{{ parseTime(detailForm.paymentDepsitTime, '{y}-{m}-{d}') }}</span>
        </el-form-item>
          </el-col>
        </el-row> -->
      <el-divider content-position="center">项目人员</el-divider>

        <el-table :data="bidProjectPresonMapList" :row-class-name="rowBidProjectPresonMapIndex">
          <el-table-column label="" align="center" prop="index" width="250"/>
          <el-table-column label="人员类别" >
            <template slot-scope="scope">
              <span>{{scope.row.personType}}</span>
            </template>
          </el-table-column>
          <el-table-column label="人员姓名" >
            <template slot-scope="scope">
            <span>{{scope.row.personName}}</span>
            </template>
          </el-table-column>
          <el-table-column label="人员是否锁定" >
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.locked"
                active-color="#ff4949" disabled>
              </el-switch>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
    </el-dialog>
  </div>
</template>



<script>
import { listBid_project, getBid_project,otherProjectPerson, delBid_project, addBid_project, updateBid_project,listBid_project_options } from "@/api/business/my_bid_project";
import { select_pms,get_person_by_type } from "@/api/business/project_person";
import { listUser_option} from "@/api/system/user";
export default {
  name: "Bid_project",
  dicts: ['sys_yes_no', 'pm_project_item_pay_type', 'pm_person_type','bid_project_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      isJxBc: false,
      isDtailJxBc: false,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedBidProjectPresonMap: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      //高级搜索
      showHighSearch: false,
      // 总条数
      total: 0,
      // 基本信息表格数据
      bid_projectList: [],
      // 项目与人员关联表格数据
      bidProjectPresonMapList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      detailOpen:false,
      // 项目人员类别时间范围
      daterangeEstimatedBidTime: [],
      // 项目人员类别时间范围
      daterangeSponsorTime: [],
      personOptions: [],
      auditorOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectNumber: null,
        region: null,
        bidForm: null,
        projectName: null,
        projectArea: null,
        address: null,
        projectCost: null,
        estimatedBidTime: null,
        constructionUnit: null,
        sponsorName: null,
        sponsorPhone: null,
        sponsorTime: null,
        paymentDepsit: null,
        depsitMoney: null,
        depsitType: null,
        tracker: null,
        auditor: null,
        bidProjectStatus: '1',
      },
      // 表单参数
      form: {},
      detailForm:{},
      // 表单校验
      rules: {
        /*projectNumber: [
          { required: true, message: "项目编号不能为空", trigger: "blur" }
        ],*/
        region: [
          { required: true, message: "区域不能为空", trigger: "blur" }
        ],
        bidForm: [
          { required: true, message: "招标形式不能为空", trigger: "blur" }
        ],
        projectName: [
          { required: true, message: "工程名称不能为空", trigger: "blur" }
        ],
        address: [
          { required: true, message: "工程地址不能为空", trigger: "blur" }
        ],
        estimatedBidTime: [
          { required: true, message: "预计投标时间不能为空", trigger: "blur" }
        ],
        constructionUnit: [
          { required: true, message: "建设单位不能为空", trigger: "blur" }
        ],
        sponsorName: [
          { required: true, message: "申办人姓名不能为空", trigger: "blur" }
        ],
        auditor: [
          { required: true, message: "审核人不能为空", trigger: "blur" }
        ],
        sponsorPhone: [
          { required: true, message: "申报人电话不能为空", trigger: "blur" },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur"
          }
        ],
        sponsorTime: [
          { required: true, message: "申办时间不能为空", trigger: "blur" }
        ],
        projectArea: [
          { required: true, validator: (rule, value, callback) => {
            if (!value) {
              callback(new Error('工程面积不能为空'))
            } else {
              if (!this.isNumber(value)) {
                callback(new Error('请输入数字值'))
              } else {
                callback()
              }
            }
          }, trigger: ["blur","change"] }
        ],
        projectCost: [
          { required: true, validator: (rule, value, callback) => {
            if (!value) {
              callback(new Error('工程造价不能为空'))
            } else {
              if (!this.isNumber(value)) {
                callback(new Error('请输入数字值'))
              } else {
                callback()
              }
            }
          }, trigger: ["blur","change"] }
        ],
        paymentDepsit: [
          { required: true, message: "是否缴纳保证金不能为空", trigger: "blur" }
        ],
        bidProjectStatus: [
          { required: true, message: "状态不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
    this.getSysUserList();
  },
  methods: {
    /** 查询基本信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeEstimatedBidTime && '' != this.daterangeEstimatedBidTime) {
        this.queryParams.params["beginEstimatedBidTime"] = this.daterangeEstimatedBidTime[0];
        this.queryParams.params["endEstimatedBidTime"] = this.daterangeEstimatedBidTime[1];
      }
      if (null != this.daterangeSponsorTime && '' != this.daterangeSponsorTime) {
        this.queryParams.params["beginSponsorTime"] = this.daterangeSponsorTime[0];
        this.queryParams.params["endSponsorTime"] = this.daterangeSponsorTime[1];
      }
      listBid_project(this.queryParams).then(response => {
        this.bid_projectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getSysUserList() {
      listUser_option().then(response => {
        this.auditorOptions = response.rows;
        this.loading = false;
      });
    },
    validPerson(val){
      let myMap = new Map();
      for (let i = 0; i < this.bidProjectPresonMapList.length; i++) {
        let tempKey = this.bidProjectPresonMapList[i].selectedPerson[0]+','+this.bidProjectPresonMapList[i].selectedPerson[1];
        if(myMap.has(tempKey)){
          this.$message.error("存在重复人员，请再次选择！");
          return;
        }else{
          myMap.set(tempKey,tempKey);
        }
      }
    },
    isNumber (val) {
      var regPos = /^\d+(\.\d+)?$/
      var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/
      if (regPos.test(val) || regNeg.test(val)) {
        return true
      } else {
        return false
      }
    },
    bclxChange(selectValue) {
      if (selectValue == 'Y') {
        this.isJxBc = true;
      } else {
        this.isJxBc = false;
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        projectId: null,
        projectNumber: null,
        region: null,
        bidForm: null,
        projectName: null,
        projectArea: null,
        address: null,
        projectCost: null,
        estimatedBidTime: null,
        constructionUnit: null,
        sponsorName: null,
        sponsorPhone: null,
        sponsorTime: null,
        paymentDepsit: null,
        depsitMoney: null,
        paymentDepsitTime: null,
        depsitType: null,
        depsitReceipt: null,
        tracker: null,
        creator: null,
        createTime: null,
        updateTime: null,
        remark: null,
        personOptions:null,
        auditor:null,
        isJxBc: false
      };
      this.detailForm = {
        projectId: null,
        projectNumber: null,
        region: null,
        bidForm: null,
        projectName: null,
        projectArea: null,
        address: null,
        projectCost: null,
        estimatedBidTime: null,
        constructionUnit: null,
        sponsorName: null,
        sponsorPhone: null,
        sponsorTime: null,
        paymentDepsit: null,
        depsitMoney: null,
        paymentDepsitTime: null,
        depsitType: null,
        depsitReceipt: null,
        tracker: null,
        creator: null,
        createTime: null,
        updateTime: null,
        remark: null,
        personOptions:null,
        auditor:null,
        isDetailJxBc: false
      };
      this.bidProjectPresonMapList = [];
      this.resetForm("form");
      this.resetForm("detailForm");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeEstimatedBidTime = [];
      this.daterangeSponsorTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.projectId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加基本信息";
      select_pms().then(response => {
        this.personOptions = response.data.cascader;
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const projectId = row.projectId || this.ids
      getBid_project(projectId).then(response => {
        this.form = response.data;
        this.bidProjectPresonMapList = response.data.bidProjectPresonMapList;
        this.personOptions = response.data.typePersonList;
        this.open = true;
        this.title = "修改基本信息";
      });
    },
    /** 修改按钮操作 */
    handleDetail(row) {
      this.reset();
      const projectId = row.projectId || this.ids
      getBid_project(projectId).then(response => {
        this.detailForm = response.data;
        this.bidProjectPresonMapList = response.data.projectPersonList;
        this.personOptions = response.data.typePersonList;
        this.detailOpen = true;
      });
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          //判断
          let myMap = new Map();
          for (let i = 0; i < this.bidProjectPresonMapList.length; i++) {
            let tempKey = this.bidProjectPresonMapList[i].selectedPerson[0]+','+this.bidProjectPresonMapList[i].selectedPerson[1];
            if(myMap.has(tempKey)){
              this.$message.error("存在重复人员，请再次选择！");
              return;
            }else{
              myMap.set(tempKey,tempKey);
            }
          }
          this.form.bidProjectPresonMapList = this.bidProjectPresonMapList;
          otherProjectPerson(this.form).then(response => {
            if(response.msg!=null&&response.msg!='操作成功'){
              this.$alert(response.msg, '错误', {
                confirmButtonText: '确定',
                type: 'error'
              });
              }else{
                if (this.form.projectId != null) {
                  updateBid_project(this.form).then(response2 => {
                    this.$modal.msgSuccess("修改成功");
                    this.open = false;
                    this.getList();
                  });
                } else {
                  addBid_project(this.form).then(response2 => {
                    this.$modal.msgSuccess("新增成功");
                    this.open = false;
                    this.getList();
                  });
                }
              }
          });
        }
      });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const projectIds = row.projectId || this.ids;
      var deleteTitle = row.projectName? ('"'+row.projectName+'"'):'';
      this.$modal.confirm('是否确认删除' + deleteTitle + '？').then(function() {
        return delBid_project(projectIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
	/** 项目与人员关联序号 */
    rowBidProjectPresonMapIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 项目与人员关联添加按钮操作 */
    handleAddBidProjectPresonMap() {
      let obj = {};
      this.bidProjectPresonMapList.push(obj);
    },
    /** 项目与人员关联删除按钮操作 */
    handleDeleteBidProjectPresonMap() {
      if (this.checkedBidProjectPresonMap.length == 0) {
        this.$modal.msgError("请先选择要删除的项目与人员关联数据");
      } else {
        const bidProjectPresonMapList = this.bidProjectPresonMapList;
        const checkedBidProjectPresonMap = this.checkedBidProjectPresonMap;
        this.bidProjectPresonMapList = bidProjectPresonMapList.filter(function(item) {
          return checkedBidProjectPresonMap.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleBidProjectPresonMapSelectionChange(selection) {
      this.checkedBidProjectPresonMap = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/bid_project/export', {
        ...this.queryParams
      }, `bid_project_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
